package com.liu.mysqldemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.liu.mysqldemo.entity.Person;
import com.liu.mysqldemo.mapper.PersonMapper;
import com.liu.mysqldemo.service.PersonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class PersonServiceImpl implements PersonService {

    @Resource
    private PersonMapper personMapper;

    @Override
    public Person addPerson(Person person) {
        int id = personMapper.insertPerson(person);
        //这里是配合mapper的insert设置才能拿到id
        Person person1 = personMapper.findPerson(person.getId());
        return person1;
    }

    @Override
    public Person removePersonByid(Long id) {
        return null;
    }

    @Override
    public Person removePerson(Person person) {
        return null;
    }

    @Override
    public Person updatePerson(Person person) {
        personMapper.updatePerson(person);
        Person person1 = personMapper.findPerson(person.getId());
        return person1;
    }

    @Override
    public Person findPersonByid(Long id) {
        Person person = personMapper.findPerson(id);
        return person;
    }

    @Override
    public Person findPersonByName(String name) {
        Person person = personMapper.findPersonByName(name);
        return person;
    }

    @Override
    public List<Map> getUnionData(String name) {
        List<Map> list = personMapper.getByParmsMap(name);
        return list;
    }

    @Override
    public List<Person> findAllpersonBypage(Integer pageIndex,Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Person> personList = personMapper.findAllpersonBypage();
        return personList;
    }
}
